<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <title>CVE漏洞详情</title>
  <link rel="stylesheet" href="/layui/css/layui.css" media="all">
  <style>
    .layui-card-header {
      border-bottom: 1px solid #f2f2f2;
      font-size: 16px;
      font-weight: bold;
      color: #333;
    }
    .layui-table {
      margin-top: 15px;
    }
    .cve-link {
      color: #1E9FFF;
    }
    .layui-badge {
      margin-right: 5px;
    }
  </style>
</head>
<body>

<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-card-header">
      <i class="layui-icon layui-icon-form"></i> 补丁关联漏洞列表
    </div>
    <div class="layui-card-body">
      <table class="layui-table">
        <colgroup>
          <col width="150">
          <col width="100">
          <col width="120">
          <col>
        </colgroup>
        <thead>
        <tr>
          <th>CVE编号</th>
          <th>CVSS评分</th>
          <th>严重等级</th>
          <th>相关补丁</th>
        </tr>
        </thead>
        <tbody id="cve-table-body">
        <!-- 数据将在这里动态加载 -->
        </tbody>
      </table>
    </div>
  </div>
</div>

<script src="/layui/layui.js"></script>
<script>
  layui.use(['jquery', 'layer'], function(){
    var $ = layui.$;
    var layer = layui.layer;

    function getQueryParam(name) {
      const urlParams = new URLSearchParams(window.location.search);
      return urlParams.get(name);
    }

    var hotfixId = getQueryParam('hotfixId');
    if (!hotfixId) {
      layer.msg('缺少hotfixId参数', {icon: 2});
      return;
    }

    // 显示加载中
    var loadIndex = layer.load(1);

    $.ajax({
      url: '/cve/detail',
      type: 'POST',
      data: { hotfixId: hotfixId },
      headers: {
        'Authorization': localStorage.getItem('token') || ''
      },
      success: function(res) {
        layer.close(loadIndex);

        if(res.code === 0 && res.data && res.data.length > 0) {
          var html = '';
          res.data.forEach(function(item) {
            html += '<tr>' +
                    '<td><a class="cve-link" href="https://nvd.nist.gov/vuln/detail/'+item.cve+'" target="_blank">'+item.cve+'</a></td>' +
                    '<td>'+ (parseFloat(item.score) || 0).toFixed(1) +'</td>' +
                    '<td>'+ getSeverityTag(item.score) +'</td>' +
                    '<td>'+ formatList(item.kbList) +'</td>' +
                    '</tr>';
          });
          $('#cve-table-body').html(html);
        } else {
          $('#cve-table-body').html('<tr><td colspan="4" style="text-align:center;color:#999">未查询到相关漏洞数据</td></tr>');
        }
      },
      error: function() {
        layer.close(loadIndex);
        layer.msg('请求失败', {icon: 2});
      }
    });

    function formatList(listStr) {
      return listStr ? listStr.split(',').join(', ') : '-';
    }

    function getSeverityTag(score) {
      score = parseFloat(score) || 0;
      if(score >= 7) return '<span class="layui-badge layui-bg-red">高危</span>';
      if(score >= 4) return '<span class="layui-badge layui-bg-orange">中危</span>';
      return '<span class="layui-badge layui-bg-green">低危</span>';
    }
  });
</script>
</body>
</html>
